package com.gjs.bedorder.control;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gjs.bedorder.business.BedInfo;

/**
 * Servlet implementation class CancelOrder
 */
@WebServlet("/cancelOrder")
public class CancelOrder extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CancelOrder() {
        super();
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		Map<String, Object> orderedBed = (Map<String, Object>) session.getAttribute("orderedBed");
		String msg = "";
		if (orderedBed == null) {
			msg = "0";
		} else {
			BedInfo.cancelOrder((String)orderedBed.get("bed_no"));
			session.removeAttribute("orderedBed");
			session.removeAttribute("msg");
			msg = (String) orderedBed.get("bed_no");
		}
		response.getWriter().append(msg);
	}

}
